<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="系统生成单号">
				<u-input v-model="dataForm.tu010" placeholder="采购单别" disabled></u-input>
			</u-form-item>


			<u-form-item label="供应商" v-if="judgeShow('tu002')">
				{{tu002Name}}
			</u-form-item>
			<u-form-item label="采购日期" v-if="judgeShow('tu003')">
				<u-input v-model="dataForm.tu003" placeholder="采购日期" :disabled="judgeWrite('tu003')"></u-input>
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('tu004')">
				<u-input v-model="dataForm.tu004" placeholder="单据日期" :disabled="judgeWrite('tu004')"></u-input>
			</u-form-item>
			<u-form-item label="客户名" v-if="judgeShow('tu006')">
				{{tu006Name}}
			</u-form-item>
			<u-form-item label="客户型号" v-if="judgeShow('tu009')">
				<u-input v-model="dataForm.tu009" placeholder="客户型号" :disabled="judgeWrite('tu009')"></u-input>
			</u-form-item>
			<u-form-item label="采购订单号" v-if="judgeShow('tu008')">
				<u-input v-model="dataForm.tu008" placeholder="采购订单号" :disabled="judgeWrite('tu008')"></u-input>
			</u-form-item>
			<u-form-item label="附件" v-if="judgeShow('tu005')">
				<jnpf-file v-model="dataForm.tu005" :disabled="judgeWrite('tu005')" />
			</u-form-item>
		</u-form>
	</view>
</template>

<script>
	import {
		getPurtu
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes,
		getUserAll,
		Interface,
	} from '@/api/common'

	import comMixin from '../mixin'
	import {
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				dataForm: {},
				id: '',
				dataForm: {},
				udf13Name: [],
				tu006Name: "",
				sourceList: [],
				ti006Name: '',
				ti007Name: '',
				tu002Name: '',
			}
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)
			},
			getInfo(data) {
				getPurtu(data.id).then(res => {
					console.log('res', res);
					if (res.code == 200) {
						this.dataForm = res.data
						this.gettu002Name(this.dataForm.tu002)
						this.gettu006Name(this.dataForm.tu006)
					}
				})
			},


			gettu002Name(id) {
				let interfaceId = '381247065990113925'
				let data = {
					id,
					interfaceId,
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.tu002Name = res.data.JoinStr;
				})
			},

			gettu006Name(id) {
				let interfaceId = '362118781926906437'
				let data = {
					id,
					interfaceId,
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.tu006Name = res.data.JoinStr;
				})
			},
			// 获取人员
			getPersonnel(id) {
				let interfaceId = '438122284524265733'
				let data = {
					id,
					interfaceId,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti007Name = res.data.JoinStr;
				})
			},
			// 获取仓库
			getWarehouse(item) {
				let interfaceId = '362114335423601221'
				let data = {
					id: item.tb008,
					interfaceId,
					propsValue: 'MC001',
					relationField: 'MC001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.$set(item, 'tb008', MC002);
					return res.data.MC002
				})
			},
			getSource() {
				getDictionaryDataSelector("474002610777559109").then(res => {
					this.sourceList = res.data.list.filter((item) => this.dataForm.ta009.includes(item.enCode))
						.map((
								item) =>
							item.fullName);
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},

		}
	}
</script>